import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
    // 读取环境配置的标准写法
    const env = loadEnv(mode, process.cwd(), '') || {}
    const {VITE_PROJECT_PREFIX} = env
    //
    return {
        plugins: [vue()],
        // 开发模式启动会以本配置为准
        server: {
            host: '127.0.0.1',
            port: 10002,
            // 注意：反向代理仅在vite开发模式下有效
            proxy: {
                '/api': {
                    target: 'http://127.0.0.1:10001',
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, "/"),
                }
            }
        },
        // 资源相对路径
        base: VITE_PROJECT_PREFIX,
    }
})
